import LogicFlow, { type Definition } from "@logicflow/core";
import { Menu, Control, DndPanel, SelectionSelect } from "@logicflow/extension";
import Tasks from "./task";
import Panels from "./panels-config";

export class BasicFlow {
	private flow: LogicFlow;
	constructor(opt: Definition) {
		this.flow = new LogicFlow({
			...opt,
			plugins: [Menu, Control, DndPanel, SelectionSelect],
		});
		Tasks.forEach(task => this.flow.register(task));
		// 添加控制栏
		this.flow.extension.dndPanel.setPatternItems(Panels(this.flow));
		this.bindEvent();
	}

	render(config: {} | undefined) {
		this.flow.render(config);
	}

	getData() {
		return this.flow.getGraphData();
	}

	private bindEvent() {
		this.flow.on("node:click, edge:click", data => {
			console.log(data, "数据,事件");
		});
	}
}
